package com.zhiyuan.firststart;

import android.content.Intent;
import android.content.SharedPreferences;
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;

public class MainActivity extends AppCompatActivity {

    public static final String PREFERENCES_NAME = "preferences_name";
    public static final String FIRST_START = "firstStart";
    private boolean firstStart = true;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        getDataFromPreferences();


        if(firstStart) {
            firstStart = false;

            saveData2Preferences();

            startActivity(new Intent(MainActivity.this, GuidePageFirstActivity.class));
        }
    }

    private void getDataFromPreferences() {
        SharedPreferences sharedPreferences = getSharedPreferences(PREFERENCES_NAME,MODE_PRIVATE);
        firstStart = sharedPreferences.getBoolean(FIRST_START,true);
    }

    private void saveData2Preferences() {
        SharedPreferences sharedPreferences = getSharedPreferences(PREFERENCES_NAME,MODE_PRIVATE);

        SharedPreferences.Editor editor = sharedPreferences.edit();

        editor.putBoolean(FIRST_START,firstStart);

        editor.commit();
    }
}
